//
//  CNCollectionNetManager.m
//  BBSModule
//
//  Created by 邓建东 on 2020/5/19.
//  Copyright © 2020 dong. All rights reserved.
//

#import "CNCollectionNetManager.h"
#import <CNBaseNetworkFramework/CNBaseNetworkFramework.h>
#import <YYCategories/YYCategories.h>


#pragma mark -添加收藏 收藏夹
NSString *const kMyCollectAddCollectFavorite = @"%@/cms-app/v1/me_folder/login/add_collect_folder";
#pragma mark -取消收藏 收藏夹
NSString *const kMyCollectDelCollectFavorite = @"%@/cms-app/v1/me_folder/login/del_collect_folder";

#pragma mark -查询是否收藏
NSString *const kMyCollectCheckFavorite = @"%@/cms-app/v1/me_folder/login/check_favorite";

#pragma mark -查询是否收藏 收藏夹
NSString *const kMyCollectCheckIsFavorite = @"%@/cms-app/v1/me_folder/login/check_folder";

#pragma mark -取消收藏
NSString *const kMyCollectDelFavorite = @"%@/cms-app/v1/me_folder/login/del_favorite";

#pragma mark -添加收藏
NSString *const kMyCollectAddFavorite = @"%@/cms-app/v1/me_folder/login/add_favorite";

#pragma mark -修改收藏夹
NSString *const kMyCollectEditFolderPath = @"%@/cms-app/v1/me_folder/login/alter_folder";

#pragma mark -添加收藏夹
NSString *const kMyCollectAddFolderPath = @"%@/cms-app/v1/me_folder/login/add_folder";

@implementation CNCollectionNetManager



/**
 添加收藏 收藏夹
 */
+ (id)addWithFolderId:(NSString *)folderId completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"favoriteId"] = folderId?:@"";
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectAddCollectFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 取消收藏 收藏夹
 */
+ (id)delWithFavoritedId:(NSString *)favoritedId  completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"favoriteId"] = favoritedId?:@"";
    
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectDelCollectFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 查询是否收藏
 
 @param url blink传id
 @param scource 来源
 @return <#return value description#>
 */
+ (id)checkFavoriteWithUrl:(NSString *)url source:(NSString *)source completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"url"] = url?:@"";
    params[@"source"] = source?:@"";
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectCheckFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_GETWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 查询是否收藏 收藏夹

 @param folderIds 收藏夹id
 @return 回调
 */
+ (id)checkFavoriteWithFolderIds:(NSString *)folderIds completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"folderIds"] = folderIds?:@"";
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectCheckIsFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_GETWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 取消收藏
 
 @param favoritedId 收藏id
 @return <#return value description#>
 */
+ (id)delFavoriteWithFavoritedId:(NSString *)favoritedId  completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"favoriteId"] = favoritedId?:@"";
    
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectDelFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 添加收藏
 
 @param folderId 收藏夹ID
 @param source 来源（blog，bbs）
 @param collectModel <#collectModel description#>
 @return <#return value description#>
 */
+ (id)addFavoriteWithFolderId:(NSString *)folderId collectionModel:(CNMineNewCollectModel *)collectModel completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"folderId"] = folderId?[NSNumber numberWithInteger:folderId.integerValue]:@"";
    params[@"source"] = collectModel.Source?:@"";
    params[@"sourceId"] = collectModel.SourceID?[NSNumber numberWithInteger:collectModel.SourceID.integerValue] :@"";
    
    params[@"author"] = collectModel.Author?:@"";
   
    
    CNMineCollectContentModel *contentModel = (CNMineCollectContentModel *)collectModel.content;
    params[@"url"] = contentModel.url?:@"";
    params[@"title"] = contentModel.title?:@"";
    params[@"description"] = contentModel.desc?:@"";
    
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectAddFavorite,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}


/**
 修改收藏夹
 @param folderName 收藏夹id
 @param folderName 收藏夹名字
 @param desc 描述
 */
+ (id)editFolderWithFolderId:(NSString *)folderId folderName:(NSString *)folderName desc:(NSString *)desc isPrivate:(BOOL)isPrivate completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"name"] = folderName?:@"";
    params[@"folderId"] = folderId?:@"";
    params[@"isPrivate"] = [NSString stringWithFormat:@"%d", isPrivate];
    if ([desc isNotBlank]) {
        params[@"description"] = desc?:@"";
    }else{
        params[@"description"] = @"";

    }
    
    BADataEntity *entiy = [[BADataEntity alloc] init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectEditFolderPath,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}

/**
 添加收藏夹
 
 @param folderName 收藏夹名字
 @param desc 描述
 */
+ (id)addFolderWithFolderName:(NSString *)folderName desc:(NSString *)desc isPrivate:(BOOL)isPrivate completionHandle:(void (^)(id, NSError *))completionHandle{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"name"] = folderName?:@"";
    params[@"isPrivate"] = [NSString stringWithFormat:@"%d", isPrivate];
    if ([desc isNotBlank]) {
        params[@"description"] = desc?:@"";
    }
   
    BADataEntity *entiy = [[BADataEntity alloc]init];
    entiy.urlString = [NSString stringWithFormat:kMyCollectAddFolderPath,[CNChangeHostManager sharedChangeHostObject].kCNALiNewHost];
    entiy.parameters = params;
    entiy.needCache = NO;
    
    return [self ba_request_POSTWithEntity:entiy successBlock:^(id response) {
        completionHandle(response,nil);
    } failureBlock:^(NSError *error) {
        completionHandle(nil,error);
    } progressBlock:nil];
}
@end
